package compiler.lexical;

import compiler.syntax.sym;
import compiler.lexical.Token;
import es.uned.lsi.compiler.lexical.ScannerIF;
import es.uned.lsi.compiler.lexical.LexicalError;
import es.uned.lsi.compiler.lexical.LexicalErrorManager;

// incluir aqui, si es necesario otras importaciones

%%
 
%public
%class Scanner
%char
%line
%column
%cup
%implements ScannerIF
%scanerror LexicalError
%state COMENTARIO

// incluir aqui, si es necesario otras directivas

%{
  LexicalErrorManager lexicalErrorManager = new LexicalErrorManager ();
%}  

%{
  private int comment_count = 0;
%} 


  
  
LineTerminator = \r | \n | \r\n
WhiteSpace = {LineTerminator} | [ \t\f]
Identificador = [A-Z,a-z]* [:jletterdigit:]*
Digito = 0 | [1-9][0-9]*  
WHITE_SPACE_CHAR=[\n\ \t\b\012]
STRING_TEXT=(\\\"|[^\n\"]|\\{WHITE_SPACE_CHAR}+\\)*

  
  
%%



<YYINITIAL> 
{
           			       
//    "+"  {  Token token = new Token (sym.PLUS); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
    
    // incluir aqui el resto de las reglas patron - accion
    



<YYINITIAL> ";"		{Token token = new Token (sym.FIN); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> ":"		{Token token = new Token (sym.DOSP); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> ".."	{Token token = new Token (sym.PP); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "("		{Token token = new Token (sym.PARI); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> ")"		{Token token = new Token (sym.PARD); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "{"		{Token token = new Token (sym.LLAVEI); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "}"		{Token token = new Token (sym.LLAVED); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "."		{Token token = new Token (sym.PUNTO); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "*"		{Token token = new Token (sym.POR); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "-"		{Token token = new Token (sym.MENOS); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "+"		{Token token = new Token (sym.MAS); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> ">"		{Token token = new Token (sym.MAYOR); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "<"		{Token token = new Token (sym.MENOR); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "="		{Token token = new Token (sym.IGUAL); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "/="	{Token token = new Token (sym.DIST); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> ":="	{Token token = new Token (sym.ASIGN); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> ","		{Token token = new Token (sym.COMA); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "and"		{Token token = new Token (sym.AND); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "array"		{Token token = new Token (sym.ARRAY); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "begin"		{Token token = new Token (sym.BEGIN); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "boolean"	{Token token = new Token (sym.BOOL); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "constant"	{Token token = new Token (sym.CONS); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "else"		{Token token = new Token (sym.ELSE); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "end"		{Token token = new Token (sym.END); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "false"		{Token token = new Token (sym.FALSE); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "for"		{Token token = new Token (sym.FOR); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "function"	{Token token = new Token (sym.FUNCTION); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "if"		{Token token = new Token (sym.IF); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "in"		{Token token = new Token (sym.IN); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "Integer"	{Token token = new Token (sym.INTEGER); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "is"		{Token token = new Token (sym.IS); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "loop"		{Token token = new Token (sym.LOOP); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "of"		{Token token = new Token (sym.OF); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "or"		{Token token = new Token (sym.OR); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "out"		{Token token = new Token (sym.OUT); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "procedure"	{Token token = new Token (sym.PROC); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "Put_line"	{Token token = new Token (sym.PUTL); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "record"	{Token token = new Token (sym.RECORD); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "return"	{Token token = new Token (sym.RETURN); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "then"		{Token token = new Token (sym.THEN); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "true"		{Token token = new Token (sym.TRUE); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "type"		{Token token = new Token (sym.TYPE); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> "while"		{Token token = new Token (sym.WHILE); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}


<YYINITIAL> {Digito}+	{Token token = new Token (sym.NUMERO); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> {Identificador}
						{Token token = new Token (sym.IDENTIFICADOR); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}
<YYINITIAL> {WhiteSpace}
						{Token token = new Token (sym.IDENTIFICADOR); token.setLine (yyline + 1); token.setColumn (yycolumn + 1);}


<YYINITIAL> \"{STRING_TEXT}\" 
	{Token token = new Token (sym.CONSTANTE); token.setLine (yyline + 1); token.setColumn (yycolumn + 1); token.setLexema (yytext ()); return token;}

<YYINITIAL> \"{STRING_TEXT} {
	String str =  yytext().substring(1,yytext().length());
	str = "Linea: " + (yyline+1)+ " Simbolo: < " + str;
	} 



<YYINITIAL> -- {STRING_TEXT}
	{}







    
    
    
    // error en caso de coincidir con ning�n patr�n
	[^]     
                        {                                               
                           LexicalError error = new LexicalError ();
                           error.setLine (yyline + 1);
                           error.setColumn (yycolumn + 1);
                           error.setLexema (yytext ());
                           lexicalErrorManager.lexicalError (error);
                        }
    
}


                         

